/**
 * jQuery封装
 * @param {string}  cssAttr css属性名
 * @param {string}  cssval  css属性值
 * @param {string}  attrName  标签属性名
 * @param {string}  attrVall  标签属性值
 * @param {string}  classVal  标签类名
 * @param {string}  inText    标签内容
 * @param {string}  elementName  标签名
 * 
 */
;(function(window, undefined){

    function init(el) {
        //获取标签对象
        let els = document.querySelectorAll(el)
        //遍历数据，将js的dom绑定到jq对象上
        for (let i = 0; i < els.length; i++) {
            // els[i] 获取js标签对象
            this[i] = els[i]
        }
        this.length = els.length
    }
    let jQuery = function (el) {
        return new init(el)
    }
    //加原型方法
    init.prototype = {
        //给标签加css样式
        css(cssAttr,cssVal){
            for (let i = 0; i < this.length; i++) {
                this[i].style[cssAttr] = cssVal
            }
            return this
        },
        //给标签加属性
        attr(attrName,attrVal) {
            for (let i = 0; i < this.length; i++) {
                this[i].setAttribute(attrName,attrVal)
            }
            return this
        },
        //给标签移除属性
        removeAttr(attrName) {
            for (let i = 0; i < this.length; i++) {
                this[i].removeAttribute(attrName)
            }
            return this
        },
        //给标签加类名
        addClass(classVal) {
            for (let i = 0; i < this.length; i++) {
                this[i].className = classVal
            }
            return this
        },
        //给标签移除类名
        removeClass(classVal){
            for (let i = 0; i < this.length; i++) {
                this[i].removeAttribute('class',classVal)
            }
            return this
        },
        //给标签加内容
        text(inText){
            for (let i = 0; i < this.length; i++) {
                this[i].innerText = inText
            }
            return this
        },
        //给指定标签追加子标签
        append(elementName){
            let eleNode = document.createElement(elementName)
            for (let i = 0; i < this.length; i++) {
                this[i].appendChild(eleNode)
            }
            return this
        }
    }
    window.jQuery = window.$ = jQuery
})(window)